package com.eq.cloud.controller;

import com.eq.cloud.entities.User;
import org.omg.CORBA.Object;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.*;


@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    private  final String url="http://localhost:8080/user";
@PostMapping
    public String add(User user){
    String result = restTemplate.postForObject(url, user, String.class);
    return result;
}

@DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id){

  restTemplate.delete(url+"/"+id);
    return "delete ok";
}

@GetMapping
public List<User> findUser(String name,Integer age){
//    Map<String, Object> map=new HashMap<>();
//    map.put("name","zhangsan");
//    map.put("age",90);
//    return restTemplate.getForObject(url+"?name=", List.class, map);
    return (List<User>) restTemplate.getForObject(url+"?name={1}&age={2}", List.class, name,age);


}
}
